// Copyright 2022 jeff.li. and/or its affiliates.

#include <gtest/gtest.h>
#include <tbir/runtime/algorithm/trie_ref.h>
#include "tbir/runtime/logging.h"

namespace tbir::runtime {

    TEST(Trie, PrefixMatch) {
        std::map<string_view, int64_t> test_data{
                {"hello world", 0},
                {"happy",       1},
                {"world",       2},
                {"hi",          3},
                {"worldhi",     4},
        };

        Trie trie(test_data);
        std::string data("world");
        int64_t index = -1;
        int len = trie.PrefixSearch(data, &index);
        ASSERT_EQ(index, 2);
        ASSERT_EQ(len, data.size());
        ASSERT_EQ(0, trie.PrefixSearch("je", &index));
        data = std::string("happy") + "world";
        auto match_len = trie.PrefixSearch(data);
        ASSERT_EQ(match_len, 5);
    }

}  // namespace tbir::runtime
